package com.eureka.healthprovider;

import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 健康检查器,用于告诉注册中心健康状态。自检
 */
@Component
public class MyHealthCheckHandler implements HealthCheckHandler {


    @Autowired
    private MyHealthIndicator myHealthIndicator;

    @Override
    public InstanceInfo.InstanceStatus getStatus(InstanceInfo.InstanceStatus instanceStatus) {
        //根据健康指标，告诉注册中心是否正常工作
        Status s = myHealthIndicator.health().getStatus();
        if (Objects.equals(s,Status.UP)){
            System.out.println("数据库 正常....");
            return InstanceInfo.InstanceStatus.UP;
        }
        System.out.println("数据库 连接失败....");
        return InstanceInfo.InstanceStatus.DOWN;
    }


}
